package org.example.weboj.mapper;

import java.util.Optional;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.example.weboj.entity.User;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wza
 * @since 2025-04-03
 */
public interface UserMapper extends BaseMapper<User> {
    @Insert("INSERT INTO user (username, email, password_hash, role, created_at) " +
            "VALUES (#{username}, #{email}, #{passwordHash}, #{role}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertUser(User user);

    @Select("SELECT * FROM user WHERE username = #{username}")
    Optional<User> findByUsername(String username);

    @Select("SELECT * FROM user WHERE email = #{email}")
    Optional<User> findByEmail(String email);
}
